<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Transformers\CategoryTransformer;
use App\Models\Category;
use App\Models\Area;
use Illuminate\Support\Arr;
class CategoriesController extends Controller
{


    public function index(Category $category, Request $request)
    {
        $categories = $category->where('is_show', true)->sortOrder()->paginate(50);
        $areas = Area::query()
                    ->withCount('movies')
                    ->orderBy('movies_count', 'desc')
                    ->limit(12)
                    ->pluck('name')
                    ->toArray();
        $areas = Arr::prepend($areas, '全部');
        return $this->response->paginator($categories, new CategoryTransformer())->addMeta('areas', $areas);
    }

    public function show(Category $category)
    {
        return $this->response->item($category, new CategoryTransformer());
    }
}
